<template>
  <div class="overlay" @click.self="closeDialog">
    <div class="dialog">
      <!-- 关闭按钮 -->
      <button class="close-btn" @click="closeDialog">×</button>

      <!-- 可滚动图片内容 -->
      <div class="scroll-container">
        <iframe
            :src="`/pdfjs-5.3.93-dist/web/viewer.html?file=${encodeURIComponent(pdfUrl)}`"
            width="100%"
            height="100%"
            frameborder="0"
        />
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineEmits, ref } from 'vue'

// 向父组件发送关闭事件
const emit = defineEmits(['close'])

const closeDialog = () => {
  emit('close')
}
// const pdfUrl = '/oss-pdf/test/pdf/test-pdf.pdf'
const pdfUrl = '/proxy-pdf/pdf.js/web/compressed.tracemonkey-pldi-09.pdf'
</script>

<style scoped>
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 999;
  display: flex;
  justify-content: center;
  align-items: center;
}

.dialog {
  position: relative;
  width: 100%;
  height: 100%;
  background: white;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 28px;
  border: none;
  background: none;
  cursor: pointer;
  z-index: 1;
}

.scroll-container {
  flex: 1;
  overflow-y: auto;
  padding-top: 60px;
}

.image-item {

  overflow: hidden;
}

.image-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
</style>
